<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace app\blog\controller;

use app\admin\model\UserModel;
use app\blog\model\BusinessModel;
use App\Http\Model\Home\goods;
use cmf\controller\AdminBaseController;
use think\Db;
class DeskTopController extends AdminBaseController
{
    public function index(){
        //查询条件
        $where = array();
        $today = strtotime(date('Y-m-d'));//获取当天时间
        
       
        
        //获取当日营业额度
        $where['utime'] = array('egt',$today); 
        $yingyee = Db::name("order")->where("payStatus=1")->where($where)->field('sum(actualMoney) as sum')->find();
        $data['yingyee'] = (int)$yingyee['sum'];
        $this->assign('data',$data);
        //获取今日订单数
        $dataa['dingdanshu'] = Db::name("order")->where("payStatus=1")->where($where)->count();
        $this->assign('dataa',$dataa);
        //获取今日商品销售数量
        $datab['goodsnum'] = Db::name("order_detail")->where("paystatus=1")->where($where)->count();
        $this->assign('datab',$datab);
        
        //获取整周的数据
        //获取本周的营业额
        $whereweek = array();
        $toone = strtotime(date("Y-m-d H:i:s",mktime(0, 0, 0,date("m"),date("d")-date("w")+1,date("Y"))));//周一
        $totwo = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))));//周日
        $whereweek['utime'] = array(array('egt',$toone),array('elt',$totwo));
        
        $weekone = Db::name("order")->where("paystatus=1")->where($whereweek)->field('sum(actualMoney) as sum')->find();
        $weekon['weekone'] = (int)$weekone['sum'];
        $this->assign('weekon',$weekon);
        //获取本周的订单数
        $weekdan['weekdan'] = Db::name("order")->where("payStatus=1")->where($whereweek)->count();
        $this->assign('weekdan',$weekdan);
        //获取本周商品销售数量
        $weekxiao['eekxiao'] = Db::name("order_detail")->where("paystatus=1")->where($whereweek)->count();
        $this->assign('weekxiao',$weekxiao);
        
        //获取本月的数据
        //获取本月的营业额
        $start = strtotime(date('Y-m-d', mktime(0,0,0,date('m'),1,date('Y'))));//获取本月的第一天
        $num = date('t',$start);//获取本月有多少天
        $end = strtotime(date('Y-m-d', mktime(0,0,0,date('m'),$num,date('Y'))));//获取本月的最后一天
        $wheremonth = array();
        $wheremonth['utime'] = array(array('egt',$start),array('elt',$end));
        
        $monthone = Db::name("order")->where("paystatus=1")->where($wheremonth)->field('sum(actualMoney) as sum')->find();
        $monthon['monthon'] = (int)$monthone['sum'];
        $this->assign('monthon',$monthon);
        
        //获取本月的订单数
        $monthdan['monthdan'] = Db::name("order_detail")->where("paystatus=1")->where($wheremonth)->count();
        $this->assign('monthdan',$monthdan);
        
        //获取本月的商品销售数量
        $monthxiao['monthxiao'] = Db::name("order_detail")->where("paystatus=1")->where($wheremonth)->count();
        $this->assign('monthxiao',$monthxiao);
        //集合数据
        //获取总的营业额
        $alwaysone = Db::name("order")->where("paystatus=1")->field('sum(actualMoney) as sum')->find();
        $alwayson['alwayson'] = (int)$alwaysone['sum'];
        $this->assign('alwayson',$alwayson);
        //获取订单数总数
        $alwaysdan['alwaysdan'] = Db::name("order_detail")->where("paystatus=1")->count();
        $this->assign('alwaysdan',$alwaysdan);
        //获取商品销售数量总数
        $alwaysxiao['alwaysxiao'] = Db::name("order_detail")->where("paystatus=1")->count();
        $this->assign('alwaysxiao',$alwaysxiao);
         //获取当前管理员所在店铺的id
        $adminid = cmf_get_current_admin_id();
        $shopid = Db::name("user")->where('id='.$adminid)->find();
        if(empty($shopid)){
            $this->success("你没有权限！", url('niu'));
        }else{
            return $this->fetch();
        }      
    }
    //射线图数据
    public function weekme(){
        $whereto = array();
        //获取每周一
        $todaying = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)));
        $whereto['utime'] = array('egt',$todaying);
        $zhourie = Db::name("order")->where("payStatus=1")->where($whereto)->field('sum(actualMoney) as sum')->find();
        $shuju = (int)$zhourie["sum"];
        //获取每周二
        $whereone = array();
        $todayone = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 2) * 24 * 3600)));
        $whereone['utime'] = array('egt',$todayone);
        $zhouone = Db::name("order")->where("payStatus=1")->where($whereone)->field('sum(actualMoney) as sum')->find();
        $shujuone = (int)$zhouone["sum"];
        //获取周三
        $wheretwo = array();
        $todaytwo = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 3) * 24 * 3600)));
        $wheretwo['utime'] = array('egt',$todaytwo);
        $zhoutwo = Db::name("order")->where("payStatus=1")->where($wheretwo)->field('sum(actualMoney) as sum')->find();
        $shujutwo = (int)$zhoutwo["sum"];
        //获取周四
        $wherethree = array();
        $todaythree = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 4) * 24 * 3600)));
        $wherethree['utime'] = array('egt',$todaythree);
        $zhouthree = Db::name("order")->where("payStatus=1")->where($wherethree)->field('sum(actualMoney) as sum')->find();
        $shujuthree = (int)$zhouthree["sum"];
        //获取周五
        $wherefour = array();
        $todayfour = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 5) * 24 * 3600)));
        $wherefour['utime'] = array('egt',$todayfour);
        $zhoufour = Db::name("order")->where("payStatus=1")->where($wherefour)->field('sum(actualMoney) as sum')->find();
        $shujufour = (int)$zhoufour["sum"];
        //获取周六
        $wherefive = array();
        $todayfive = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 6) * 24 * 3600)));
        $wherefive['utime'] = array('egt',$todayfive);
        $zhoufive = Db::name("order")->where("payStatus=1")->where($wherefive)->field('sum(actualMoney) as sum')->find();
        $shujufive = (int)$zhoufive["sum"];
        //获取周日
        $wheresix = array();
        $todaysix = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 7) * 24 * 3600)));
        $wheresix['utime'] = array('egt',$todaysix);
        $zhousix = Db::name("order")->where("payStatus=1")->where($wheresix)->field('sum(actualMoney) as sum')->find();
        $shujusix = (int)$zhousix["sum"];
        $gather = array($shuju,$shujuone,$shujutwo,$shujuthree,$shujufour,$shujufive,$shujusix);
        //$jsonStr = json_encode($gather);
        //var_dump($gather);exit;
        return $this->success($gather);
    }
    public function niu(){
        return $this->fetch();
    }
}
























